﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using GPSTrackingDBV2.Entities;
using GPSTrackingDBV2.Data;

#endregion

namespace GPSTrackingDBV2.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="GpsGroupsProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class GpsGroupsProviderBaseCore : EntityProviderBase<GPSTrackingDBV2.Entities.GpsGroups, GPSTrackingDBV2.Entities.GpsGroupsKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByBusRouteIdFromBusRouteByGpsGroups
		
		/// <summary>
		///		Gets GPSGroups objects from the datasource by BusRouteID in the
		///		BusRouteByGPSGroups table. Table GPSGroups is related to table BusRoutes
		///		through the (M:N) relationship defined in the BusRouteByGPSGroups table.
		/// </summary>
		/// <param name="_busRouteId"></param>
		/// <returns>Returns a typed collection of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByBusRouteIdFromBusRouteByGpsGroups(System.Int32 _busRouteId)
		{
			int count = -1;
			return GetByBusRouteIdFromBusRouteByGpsGroups(null,_busRouteId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GpsGroups objects from the datasource by BusRouteID in the
		///		BusRouteByGPSGroups table. Table GPSGroups is related to table BusRoutes
		///		through the (M:N) relationship defined in the BusRouteByGPSGroups table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_busRouteId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByBusRouteIdFromBusRouteByGpsGroups(System.Int32 _busRouteId, int start, int pageLength)
		{
			int count = -1;
			return GetByBusRouteIdFromBusRouteByGpsGroups(null, _busRouteId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by BusRouteID in the
		///		BusRouteByGPSGroups table. Table GPSGroups is related to table BusRoutes
		///		through the (M:N) relationship defined in the BusRouteByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_busRouteId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByBusRouteIdFromBusRouteByGpsGroups(TransactionManager transactionManager, System.Int32 _busRouteId)
		{
			int count = -1;
			return GetByBusRouteIdFromBusRouteByGpsGroups(transactionManager, _busRouteId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by BusRouteID in the
		///		BusRouteByGPSGroups table. Table GPSGroups is related to table BusRoutes
		///		through the (M:N) relationship defined in the BusRouteByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_busRouteId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByBusRouteIdFromBusRouteByGpsGroups(TransactionManager transactionManager, System.Int32 _busRouteId,int start, int pageLength)
		{
			int count = -1;
			return GetByBusRouteIdFromBusRouteByGpsGroups(transactionManager, _busRouteId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by BusRouteID in the
		///		BusRouteByGPSGroups table. Table GPSGroups is related to table BusRoutes
		///		through the (M:N) relationship defined in the BusRouteByGPSGroups table.
		/// </summary>
		/// <param name="_busRouteId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByBusRouteIdFromBusRouteByGpsGroups(System.Int32 _busRouteId,int start, int pageLength, out int count)
		{
			
			return GetByBusRouteIdFromBusRouteByGpsGroups(null, _busRouteId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GPSGroups objects from the datasource by BusRouteID in the
		///		BusRouteByGPSGroups table. Table GPSGroups is related to table BusRoutes
		///		through the (M:N) relationship defined in the BusRouteByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_busRouteId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public abstract TList<GpsGroups> GetByBusRouteIdFromBusRouteByGpsGroups(TransactionManager transactionManager,System.Int32 _busRouteId, int start, int pageLength, out int count);
		
		#endregion GetByBusRouteIdFromBusRouteByGpsGroups
		
		#region GetByCompanyIdFromCompaniesByGpsGroups
		
		/// <summary>
		///		Gets GPSGroups objects from the datasource by CompanyID in the
		///		CompaniesByGPSGroups table. Table GPSGroups is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGPSGroups table.
		/// </summary>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByCompanyIdFromCompaniesByGpsGroups(System.Int32 _companyId)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGpsGroups(null,_companyId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GpsGroups objects from the datasource by CompanyID in the
		///		CompaniesByGPSGroups table. Table GPSGroups is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGPSGroups table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByCompanyIdFromCompaniesByGpsGroups(System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGpsGroups(null, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by CompanyID in the
		///		CompaniesByGPSGroups table. Table GPSGroups is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByCompanyIdFromCompaniesByGpsGroups(TransactionManager transactionManager, System.Int32 _companyId)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGpsGroups(transactionManager, _companyId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by CompanyID in the
		///		CompaniesByGPSGroups table. Table GPSGroups is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByCompanyIdFromCompaniesByGpsGroups(TransactionManager transactionManager, System.Int32 _companyId,int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGpsGroups(transactionManager, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by CompanyID in the
		///		CompaniesByGPSGroups table. Table GPSGroups is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGPSGroups table.
		/// </summary>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByCompanyIdFromCompaniesByGpsGroups(System.Int32 _companyId,int start, int pageLength, out int count)
		{
			
			return GetByCompanyIdFromCompaniesByGpsGroups(null, _companyId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GPSGroups objects from the datasource by CompanyID in the
		///		CompaniesByGPSGroups table. Table GPSGroups is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public abstract TList<GpsGroups> GetByCompanyIdFromCompaniesByGpsGroups(TransactionManager transactionManager,System.Int32 _companyId, int start, int pageLength, out int count);
		
		#endregion GetByCompanyIdFromCompaniesByGpsGroups
		
		#region GetByGpsImeiFromGpsStockByGpsGroups
		
		/// <summary>
		///		Gets GPSGroups objects from the datasource by GPSImei in the
		///		GPSStockByGPSGroups table. Table GPSGroups is related to table GPSStock
		///		through the (M:N) relationship defined in the GPSStockByGPSGroups table.
		/// </summary>
		/// <param name="_gpsImei"></param>
		/// <returns>Returns a typed collection of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByGpsImeiFromGpsStockByGpsGroups(System.String _gpsImei)
		{
			int count = -1;
			return GetByGpsImeiFromGpsStockByGpsGroups(null,_gpsImei, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GpsGroups objects from the datasource by GPSImei in the
		///		GPSStockByGPSGroups table. Table GPSGroups is related to table GPSStock
		///		through the (M:N) relationship defined in the GPSStockByGPSGroups table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByGpsImeiFromGpsStockByGpsGroups(System.String _gpsImei, int start, int pageLength)
		{
			int count = -1;
			return GetByGpsImeiFromGpsStockByGpsGroups(null, _gpsImei, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by GPSImei in the
		///		GPSStockByGPSGroups table. Table GPSGroups is related to table GPSStock
		///		through the (M:N) relationship defined in the GPSStockByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByGpsImeiFromGpsStockByGpsGroups(TransactionManager transactionManager, System.String _gpsImei)
		{
			int count = -1;
			return GetByGpsImeiFromGpsStockByGpsGroups(transactionManager, _gpsImei, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by GPSImei in the
		///		GPSStockByGPSGroups table. Table GPSGroups is related to table GPSStock
		///		through the (M:N) relationship defined in the GPSStockByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsImei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByGpsImeiFromGpsStockByGpsGroups(TransactionManager transactionManager, System.String _gpsImei,int start, int pageLength)
		{
			int count = -1;
			return GetByGpsImeiFromGpsStockByGpsGroups(transactionManager, _gpsImei, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by GPSImei in the
		///		GPSStockByGPSGroups table. Table GPSGroups is related to table GPSStock
		///		through the (M:N) relationship defined in the GPSStockByGPSGroups table.
		/// </summary>
		/// <param name="_gpsImei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByGpsImeiFromGpsStockByGpsGroups(System.String _gpsImei,int start, int pageLength, out int count)
		{
			
			return GetByGpsImeiFromGpsStockByGpsGroups(null, _gpsImei, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GPSGroups objects from the datasource by GPSImei in the
		///		GPSStockByGPSGroups table. Table GPSGroups is related to table GPSStock
		///		through the (M:N) relationship defined in the GPSStockByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public abstract TList<GpsGroups> GetByGpsImeiFromGpsStockByGpsGroups(TransactionManager transactionManager,System.String _gpsImei, int start, int pageLength, out int count);
		
		#endregion GetByGpsImeiFromGpsStockByGpsGroups
		
		#region GetByUsernameCompanyIdFromUsersByGpsGroups
		
		/// <summary>
		///		Gets GPSGroups objects from the datasource by Username in the
		///		UsersByGPSGroups table. Table GPSGroups is related to table Users
		///		through the (M:N) relationship defined in the UsersByGPSGroups table.
		/// </summary>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByUsernameCompanyIdFromUsersByGpsGroups(System.String _username, System.Int32 _companyId)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromUsersByGpsGroups(null,_username, _companyId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GpsGroups objects from the datasource by Username in the
		///		UsersByGPSGroups table. Table GPSGroups is related to table Users
		///		through the (M:N) relationship defined in the UsersByGPSGroups table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public TList<GpsGroups> GetByUsernameCompanyIdFromUsersByGpsGroups(System.String _username, System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromUsersByGpsGroups(null, _username, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by Username in the
		///		UsersByGPSGroups table. Table GPSGroups is related to table Users
		///		through the (M:N) relationship defined in the UsersByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByUsernameCompanyIdFromUsersByGpsGroups(TransactionManager transactionManager, System.String _username, System.Int32 _companyId)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromUsersByGpsGroups(transactionManager, _username, _companyId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by Username in the
		///		UsersByGPSGroups table. Table GPSGroups is related to table Users
		///		through the (M:N) relationship defined in the UsersByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByUsernameCompanyIdFromUsersByGpsGroups(TransactionManager transactionManager, System.String _username, System.Int32 _companyId,int start, int pageLength)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromUsersByGpsGroups(transactionManager, _username, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GpsGroups objects from the datasource by Username in the
		///		UsersByGPSGroups table. Table GPSGroups is related to table Users
		///		through the (M:N) relationship defined in the UsersByGPSGroups table.
		/// </summary>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSGroups objects.</returns>
		public TList<GpsGroups> GetByUsernameCompanyIdFromUsersByGpsGroups(System.String _username, System.Int32 _companyId,int start, int pageLength, out int count)
		{
			
			return GetByUsernameCompanyIdFromUsersByGpsGroups(null, _username, _companyId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GPSGroups objects from the datasource by Username in the
		///		UsersByGPSGroups table. Table GPSGroups is related to table Users
		///		through the (M:N) relationship defined in the UsersByGPSGroups table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GpsGroups objects.</returns>
		public abstract TList<GpsGroups> GetByUsernameCompanyIdFromUsersByGpsGroups(TransactionManager transactionManager,System.String _username, System.Int32 _companyId, int start, int pageLength, out int count);
		
		#endregion GetByUsernameCompanyIdFromUsersByGpsGroups
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GpsGroupsKey key)
		{
			return Delete(transactionManager, key.GpsGroupId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_gpsGroupId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _gpsGroupId)
		{
			return Delete(null, _gpsGroupId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsGroupId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _gpsGroupId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override GPSTrackingDBV2.Entities.GpsGroups Get(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GpsGroupsKey key, int start, int pageLength)
		{
			return GetByGpsGroupId(transactionManager, key.GpsGroupId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_GPSGroups index.
		/// </summary>
		/// <param name="_gpsGroupId"></param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> class.</returns>
		public GPSTrackingDBV2.Entities.GpsGroups GetByGpsGroupId(System.Int32 _gpsGroupId)
		{
			int count = -1;
			return GetByGpsGroupId(null,_gpsGroupId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GPSGroups index.
		/// </summary>
		/// <param name="_gpsGroupId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> class.</returns>
		public GPSTrackingDBV2.Entities.GpsGroups GetByGpsGroupId(System.Int32 _gpsGroupId, int start, int pageLength)
		{
			int count = -1;
			return GetByGpsGroupId(null, _gpsGroupId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GPSGroups index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsGroupId"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> class.</returns>
		public GPSTrackingDBV2.Entities.GpsGroups GetByGpsGroupId(TransactionManager transactionManager, System.Int32 _gpsGroupId)
		{
			int count = -1;
			return GetByGpsGroupId(transactionManager, _gpsGroupId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GPSGroups index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsGroupId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> class.</returns>
		public GPSTrackingDBV2.Entities.GpsGroups GetByGpsGroupId(TransactionManager transactionManager, System.Int32 _gpsGroupId, int start, int pageLength)
		{
			int count = -1;
			return GetByGpsGroupId(transactionManager, _gpsGroupId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GPSGroups index.
		/// </summary>
		/// <param name="_gpsGroupId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> class.</returns>
		public GPSTrackingDBV2.Entities.GpsGroups GetByGpsGroupId(System.Int32 _gpsGroupId, int start, int pageLength, out int count)
		{
			return GetByGpsGroupId(null, _gpsGroupId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GPSGroups index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsGroupId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> class.</returns>
		public abstract GPSTrackingDBV2.Entities.GpsGroups GetByGpsGroupId(TransactionManager transactionManager, System.Int32 _gpsGroupId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;GpsGroups&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;GpsGroups&gt;"/></returns>
		public static TList<GpsGroups> Fill(IDataReader reader, TList<GpsGroups> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				GPSTrackingDBV2.Entities.GpsGroups c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("GpsGroups")
					.Append("|").Append((System.Int32)reader[((int)GpsGroupsColumn.GpsGroupId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<GpsGroups>(
					key.ToString(), // EntityTrackingKey
					"GpsGroups",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new GPSTrackingDBV2.Entities.GpsGroups();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.GpsGroupId = (System.Int32)reader[((int)GpsGroupsColumn.GpsGroupId - 1)];
					c.OriginalGpsGroupId = c.GpsGroupId;
					c.Name = (System.String)reader[((int)GpsGroupsColumn.Name - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, GPSTrackingDBV2.Entities.GpsGroups entity)
		{
			if (!reader.Read()) return;
			
			entity.GpsGroupId = (System.Int32)reader[((int)GpsGroupsColumn.GpsGroupId - 1)];
			entity.OriginalGpsGroupId = (System.Int32)reader["GPSGroupID"];
			entity.Name = (System.String)reader[((int)GpsGroupsColumn.Name - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, GPSTrackingDBV2.Entities.GpsGroups entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.GpsGroupId = (System.Int32)dataRow["GPSGroupID"];
			entity.OriginalGpsGroupId = (System.Int32)dataRow["GPSGroupID"];
			entity.Name = (System.String)dataRow["Name"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.GpsGroups"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.GpsGroups Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GpsGroups entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByGpsGroupId methods when available
			
			#region GpsImeiGpsStockCollection_From_GpsStockByGpsGroups
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<GpsStock>|GpsImeiGpsStockCollection_From_GpsStockByGpsGroups", deepLoadType, innerList))
			{
				entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups = DataRepository.GpsStockProvider.GetByGpsGroupIdFromGpsStockByGpsGroups(transactionManager, entity.GpsGroupId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GpsImeiGpsStockCollection_From_GpsStockByGpsGroups' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups != null)
				{
					deepHandles.Add("GpsImeiGpsStockCollection_From_GpsStockByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< GpsStock >) DataRepository.GpsStockProvider.DeepLoad,
						new object[] { transactionManager, entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region CompaniesByGpsGroupsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<CompaniesByGpsGroups>|CompaniesByGpsGroupsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompaniesByGpsGroupsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.CompaniesByGpsGroupsCollection = DataRepository.CompaniesByGpsGroupsProvider.GetByGpsGroupId(transactionManager, entity.GpsGroupId);

				if (deep && entity.CompaniesByGpsGroupsCollection.Count > 0)
				{
					deepHandles.Add("CompaniesByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<CompaniesByGpsGroups>) DataRepository.CompaniesByGpsGroupsProvider.DeepLoad,
						new object[] { transactionManager, entity.CompaniesByGpsGroupsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region BusRouteByGpsGroupsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<BusRouteByGpsGroups>|BusRouteByGpsGroupsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'BusRouteByGpsGroupsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.BusRouteByGpsGroupsCollection = DataRepository.BusRouteByGpsGroupsProvider.GetByGpsGroupId(transactionManager, entity.GpsGroupId);

				if (deep && entity.BusRouteByGpsGroupsCollection.Count > 0)
				{
					deepHandles.Add("BusRouteByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<BusRouteByGpsGroups>) DataRepository.BusRouteByGpsGroupsProvider.DeepLoad,
						new object[] { transactionManager, entity.BusRouteByGpsGroupsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region UsersByGpsGroupsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<UsersByGpsGroups>|UsersByGpsGroupsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'UsersByGpsGroupsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.UsersByGpsGroupsCollection = DataRepository.UsersByGpsGroupsProvider.GetByGpsGroupId(transactionManager, entity.GpsGroupId);

				if (deep && entity.UsersByGpsGroupsCollection.Count > 0)
				{
					deepHandles.Add("UsersByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<UsersByGpsGroups>) DataRepository.UsersByGpsGroupsProvider.DeepLoad,
						new object[] { transactionManager, entity.UsersByGpsGroupsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region GpsStockByGpsGroupsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<GpsStockByGpsGroups>|GpsStockByGpsGroupsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GpsStockByGpsGroupsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.GpsStockByGpsGroupsCollection = DataRepository.GpsStockByGpsGroupsProvider.GetByGpsGroupId(transactionManager, entity.GpsGroupId);

				if (deep && entity.GpsStockByGpsGroupsCollection.Count > 0)
				{
					deepHandles.Add("GpsStockByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<GpsStockByGpsGroups>) DataRepository.GpsStockByGpsGroupsProvider.DeepLoad,
						new object[] { transactionManager, entity.GpsStockByGpsGroupsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<BusRoutes>|BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups", deepLoadType, innerList))
			{
				entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups = DataRepository.BusRoutesProvider.GetByGpsGroupIdFromBusRouteByGpsGroups(transactionManager, entity.GpsGroupId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups != null)
				{
					deepHandles.Add("BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< BusRoutes >) DataRepository.BusRoutesProvider.DeepLoad,
						new object[] { transactionManager, entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region CompanyIdCompaniesCollection_From_CompaniesByGpsGroups
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Companies>|CompanyIdCompaniesCollection_From_CompaniesByGpsGroups", deepLoadType, innerList))
			{
				entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups = DataRepository.CompaniesProvider.GetByGpsGroupIdFromCompaniesByGpsGroups(transactionManager, entity.GpsGroupId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompanyIdCompaniesCollection_From_CompaniesByGpsGroups' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups != null)
				{
					deepHandles.Add("CompanyIdCompaniesCollection_From_CompaniesByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Companies >) DataRepository.CompaniesProvider.DeepLoad,
						new object[] { transactionManager, entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region UsernameCompanyIdUsersCollection_From_UsersByGpsGroups
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Users>|UsernameCompanyIdUsersCollection_From_UsersByGpsGroups", deepLoadType, innerList))
			{
				entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups = DataRepository.UsersProvider.GetByGpsGroupIdFromUsersByGpsGroups(transactionManager, entity.GpsGroupId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'UsernameCompanyIdUsersCollection_From_UsersByGpsGroups' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups != null)
				{
					deepHandles.Add("UsernameCompanyIdUsersCollection_From_UsersByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Users >) DataRepository.UsersProvider.DeepLoad,
						new object[] { transactionManager, entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the GPSTrackingDBV2.Entities.GpsGroups object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">GPSTrackingDBV2.Entities.GpsGroups instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.GpsGroups Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GpsGroups entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region GpsImeiGpsStockCollection_From_GpsStockByGpsGroups>
			if (CanDeepSave(entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups, "List<GpsStock>|GpsImeiGpsStockCollection_From_GpsStockByGpsGroups", deepSaveType, innerList))
			{
				if (entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups.Count > 0 || entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups.DeletedItems.Count > 0)
				{
					DataRepository.GpsStockProvider.Save(transactionManager, entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups); 
					deepHandles.Add("GpsImeiGpsStockCollection_From_GpsStockByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<GpsStock>) DataRepository.GpsStockProvider.DeepSave,
						new object[] { transactionManager, entity.GpsImeiGpsStockCollection_From_GpsStockByGpsGroups, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups>
			if (CanDeepSave(entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups, "List<BusRoutes>|BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups", deepSaveType, innerList))
			{
				if (entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups.Count > 0 || entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups.DeletedItems.Count > 0)
				{
					DataRepository.BusRoutesProvider.Save(transactionManager, entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups); 
					deepHandles.Add("BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<BusRoutes>) DataRepository.BusRoutesProvider.DeepSave,
						new object[] { transactionManager, entity.BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region CompanyIdCompaniesCollection_From_CompaniesByGpsGroups>
			if (CanDeepSave(entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups, "List<Companies>|CompanyIdCompaniesCollection_From_CompaniesByGpsGroups", deepSaveType, innerList))
			{
				if (entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups.Count > 0 || entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups.DeletedItems.Count > 0)
				{
					DataRepository.CompaniesProvider.Save(transactionManager, entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups); 
					deepHandles.Add("CompanyIdCompaniesCollection_From_CompaniesByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Companies>) DataRepository.CompaniesProvider.DeepSave,
						new object[] { transactionManager, entity.CompanyIdCompaniesCollection_From_CompaniesByGpsGroups, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region UsernameCompanyIdUsersCollection_From_UsersByGpsGroups>
			if (CanDeepSave(entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups, "List<Users>|UsernameCompanyIdUsersCollection_From_UsersByGpsGroups", deepSaveType, innerList))
			{
				if (entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups.Count > 0 || entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups.DeletedItems.Count > 0)
				{
					DataRepository.UsersProvider.Save(transactionManager, entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups); 
					deepHandles.Add("UsernameCompanyIdUsersCollection_From_UsersByGpsGroups",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Users>) DataRepository.UsersProvider.DeepSave,
						new object[] { transactionManager, entity.UsernameCompanyIdUsersCollection_From_UsersByGpsGroups, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 
	
			#region List<CompaniesByGpsGroups>
				if (CanDeepSave(entity.CompaniesByGpsGroupsCollection, "List<CompaniesByGpsGroups>|CompaniesByGpsGroupsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(CompaniesByGpsGroups child in entity.CompaniesByGpsGroupsCollection)
					{
						if(child.GpsGroupIdSource != null)
						{
								child.GpsGroupId = child.GpsGroupIdSource.GpsGroupId;
						}

						if(child.CompanyIdSource != null)
						{
								child.CompanyId = child.CompanyIdSource.CompanyId;
						}

					}

					if (entity.CompaniesByGpsGroupsCollection.Count > 0 || entity.CompaniesByGpsGroupsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.CompaniesByGpsGroupsProvider.Save(transactionManager, entity.CompaniesByGpsGroupsCollection);
						
						deepHandles.Add("CompaniesByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< CompaniesByGpsGroups >) DataRepository.CompaniesByGpsGroupsProvider.DeepSave,
							new object[] { transactionManager, entity.CompaniesByGpsGroupsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<BusRouteByGpsGroups>
				if (CanDeepSave(entity.BusRouteByGpsGroupsCollection, "List<BusRouteByGpsGroups>|BusRouteByGpsGroupsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(BusRouteByGpsGroups child in entity.BusRouteByGpsGroupsCollection)
					{
						if(child.GpsGroupIdSource != null)
						{
								child.GpsGroupId = child.GpsGroupIdSource.GpsGroupId;
						}

						if(child.BusRouteIdSource != null)
						{
								child.BusRouteId = child.BusRouteIdSource.BusRouteId;
						}

					}

					if (entity.BusRouteByGpsGroupsCollection.Count > 0 || entity.BusRouteByGpsGroupsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.BusRouteByGpsGroupsProvider.Save(transactionManager, entity.BusRouteByGpsGroupsCollection);
						
						deepHandles.Add("BusRouteByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< BusRouteByGpsGroups >) DataRepository.BusRouteByGpsGroupsProvider.DeepSave,
							new object[] { transactionManager, entity.BusRouteByGpsGroupsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<UsersByGpsGroups>
				if (CanDeepSave(entity.UsersByGpsGroupsCollection, "List<UsersByGpsGroups>|UsersByGpsGroupsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(UsersByGpsGroups child in entity.UsersByGpsGroupsCollection)
					{
						if(child.GpsGroupIdSource != null)
						{
								child.GpsGroupId = child.GpsGroupIdSource.GpsGroupId;
						}

						if(child.UsernameCompanyIdSource != null)
						{
								child.Username = child.UsernameCompanyIdSource.Username;
								child.CompanyId = child.UsernameCompanyIdSource.CompanyId;
						}

					}

					if (entity.UsersByGpsGroupsCollection.Count > 0 || entity.UsersByGpsGroupsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.UsersByGpsGroupsProvider.Save(transactionManager, entity.UsersByGpsGroupsCollection);
						
						deepHandles.Add("UsersByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< UsersByGpsGroups >) DataRepository.UsersByGpsGroupsProvider.DeepSave,
							new object[] { transactionManager, entity.UsersByGpsGroupsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<GpsStockByGpsGroups>
				if (CanDeepSave(entity.GpsStockByGpsGroupsCollection, "List<GpsStockByGpsGroups>|GpsStockByGpsGroupsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(GpsStockByGpsGroups child in entity.GpsStockByGpsGroupsCollection)
					{
						if(child.GpsGroupIdSource != null)
						{
								child.GpsGroupId = child.GpsGroupIdSource.GpsGroupId;
						}

						if(child.GpsImeiSource != null)
						{
								child.GpsImei = child.GpsImeiSource.GpsImei;
						}

					}

					if (entity.GpsStockByGpsGroupsCollection.Count > 0 || entity.GpsStockByGpsGroupsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.GpsStockByGpsGroupsProvider.Save(transactionManager, entity.GpsStockByGpsGroupsCollection);
						
						deepHandles.Add("GpsStockByGpsGroupsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< GpsStockByGpsGroups >) DataRepository.GpsStockByGpsGroupsProvider.DeepSave,
							new object[] { transactionManager, entity.GpsStockByGpsGroupsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region GpsGroupsChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>GPSTrackingDBV2.Entities.GpsGroups</c>
	///</summary>
	public enum GpsGroupsChildEntityTypes
	{

		///<summary>
		/// Collection of <c>GpsGroups</c> as ManyToMany for GpsStockCollection_From_GpsStockByGpsGroups
		///</summary>
		[ChildEntityType(typeof(TList<GpsStock>))]
		GpsImeiGpsStockCollection_From_GpsStockByGpsGroups,

		///<summary>
		/// Collection of <c>GpsGroups</c> as OneToMany for CompaniesByGpsGroupsCollection
		///</summary>
		[ChildEntityType(typeof(TList<CompaniesByGpsGroups>))]
		CompaniesByGpsGroupsCollection,

		///<summary>
		/// Collection of <c>GpsGroups</c> as OneToMany for BusRouteByGpsGroupsCollection
		///</summary>
		[ChildEntityType(typeof(TList<BusRouteByGpsGroups>))]
		BusRouteByGpsGroupsCollection,

		///<summary>
		/// Collection of <c>GpsGroups</c> as OneToMany for UsersByGpsGroupsCollection
		///</summary>
		[ChildEntityType(typeof(TList<UsersByGpsGroups>))]
		UsersByGpsGroupsCollection,

		///<summary>
		/// Collection of <c>GpsGroups</c> as OneToMany for GpsStockByGpsGroupsCollection
		///</summary>
		[ChildEntityType(typeof(TList<GpsStockByGpsGroups>))]
		GpsStockByGpsGroupsCollection,

		///<summary>
		/// Collection of <c>GpsGroups</c> as ManyToMany for BusRoutesCollection_From_BusRouteByGpsGroups
		///</summary>
		[ChildEntityType(typeof(TList<BusRoutes>))]
		BusRouteIdBusRoutesCollection_From_BusRouteByGpsGroups,

		///<summary>
		/// Collection of <c>GpsGroups</c> as ManyToMany for CompaniesCollection_From_CompaniesByGpsGroups
		///</summary>
		[ChildEntityType(typeof(TList<Companies>))]
		CompanyIdCompaniesCollection_From_CompaniesByGpsGroups,

		///<summary>
		/// Collection of <c>GpsGroups</c> as ManyToMany for UsersCollection_From_UsersByGpsGroups
		///</summary>
		[ChildEntityType(typeof(TList<Users>))]
		UsernameCompanyIdUsersCollection_From_UsersByGpsGroups,
	}
	
	#endregion GpsGroupsChildEntityTypes
	
	#region GpsGroupsFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;GpsGroupsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="GpsGroups"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class GpsGroupsFilterBuilder : SqlFilterBuilder<GpsGroupsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GpsGroupsFilterBuilder class.
		/// </summary>
		public GpsGroupsFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the GpsGroupsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public GpsGroupsFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the GpsGroupsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public GpsGroupsFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion GpsGroupsFilterBuilder
	
	#region GpsGroupsParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;GpsGroupsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="GpsGroups"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class GpsGroupsParameterBuilder : ParameterizedSqlFilterBuilder<GpsGroupsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GpsGroupsParameterBuilder class.
		/// </summary>
		public GpsGroupsParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the GpsGroupsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public GpsGroupsParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the GpsGroupsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public GpsGroupsParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion GpsGroupsParameterBuilder
	
	#region GpsGroupsSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;GpsGroupsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="GpsGroups"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class GpsGroupsSortBuilder : SqlSortBuilder<GpsGroupsColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GpsGroupsSqlSortBuilder class.
		/// </summary>
		public GpsGroupsSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion GpsGroupsSortBuilder
	
} // end namespace
